package com.yuwei.mine

import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils
import com.yuwei.base.RoutePath
import com.yuwei.common.mvi.BaseMviActivity
import com.yuwei.common.mvi.UiState
import com.yuwei.database.entity.GoodsEntityItem
import com.yuwei.mine.adapter.HistoryAdapter
import com.yuwei.mine.databinding.ActivityOrdersBinding

@Route(path = RoutePath.MODULE_MINE_ORDERS_ACTIVITY)
class OrdersActivity : BaseMviActivity<ActivityOrdersBinding,MineViewModel>() {
    private val historyAdapter = HistoryAdapter()
    override fun successData(it: UiState.onSuccess<*>) {
        when(it.type){
            "getHistory"->{
                historyAdapter.data.addAll(it.data as List<GoodsEntityItem>)
                historyAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun failureData(error: String) {

    }

    override fun initView() {
        vm.sendIntent(MineIntent.getHistory)
        binding.ivBack.setOnClickListener {
            finish()
        }
        binding.tvFind.setOnClickListener {
            ARouter.getInstance().build(RoutePath.MODULE_MINE_ALL_ORDERS_ACTIVITY).navigation()
        }
        binding.historyRv.adapter = historyAdapter
        binding.historyRv.layoutManager = GridLayoutManager(this,2)
    }

    override fun initData() {

    }
}